<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function getlist(){
				//1.创建xhr异步对象
				var xhr=new XMLHttpRequest();
				//4.创建监听，接收响应
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var r=xhr.responseText;
						var arr=JSON.parse(r);
						//table的结构字符串--------1.表头
					var htmlStr=`
					<table border="1" bordercolor="purple" bgcolor="pink" width="800" align="center">
								 <tr>
									<th>编号</th>
									 <th>接收人姓名</th>
									 <th>省</th>
									 <th>市</th>
									 <th>县</th>
									 <th>详细地址</th>
									 <th>手机</th>
									 <th>邮编</th>
									 <th>操作</th>
								 </tr>
					`;	
					//table的结构字符串--------2.循环
					for(var i=0;i<arr.length;i++){
						var sex="保密";
						if(arr[i].gender==1){
							sex="男";
						}else if(arr[i].gender==0){
							sex="女";
						}else{
							sex="保密";
						}
						htmlStr+=`
								<tr>
									<td>${arr[i].user_id}</td>
								  <td>${arr[i].receiver}</td>
								  <td>${arr[i].province}</td>
								  <td>${arr[i].city}</td>
								  <td>${arr[i].county}</td>
								  <td>${arr[i].address}</td>
								  <td>${arr[i].cellphone}</td>
								  <td>${arr[i].postcode}</td>
							    <td>
										<a href="address_search.html?user_id=${arr[i].user_id}">修改</a>
										<a href="javascript:delUser(${arr[i].user_id})">删除</a>
									</td>
								</tr>
							`;
						}
						//table的结构字符串--------3.表结束
						htmlStr+="</table>";
						d1.innerHTML=htmlStr;
					}
				}
				//2.创建请求，打开连接
					xhr.open("get",`/address/v1/search`,true);
					//3.发送请求
					xhr.send();
				}
	  function delUser($user_id){
			var xhr=new XMLHttpRequest();
			xhr.open("delete",`/address/v1/address_del/${$user_id}`,true);
			xhr.send();
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4 && xhr.status==200){
					var r=xhr.responseText;
					if(r==1){
						alert("删除成功");
						location.href="user_address_put.html"
					}else{
						alert("删除失败")
					}
				}
			}
			
			
		}
		</script>
	</head>
	<body onload="getlist()">
		<div id="d1"></div>
	</body>
</html>
